import pymysql.cursors

connecton = pymysql.connect(host='localhost',
                            user='root',
                            password='',
                            db='test',
                            cursorclass=pymysql.cursors.DictCursor)

try:
    with connecton.cursor() as cursor:
        sql = 'SELECT * FROM user'
        cursor.execute(sql)
        print cursor.fetchall()

    with connecton.cursor() as cursor:
        sql = "INSERT INTO user VALUES (%s, %s)"
        cursor.execute(sql, (5, 'zhu'))

    connecton.commit()

finally:
    connecton.close()
